package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.BatchSetting;
import com.example.mybatisplus.model.domain.UserManage;
import com.example.mybatisplus.model.domain.WhitelistSetting;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.BatchSettingService;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 *
 *  前端控制器
 *
 *
 * @author sharplu
 * @since 2023-07-10
 * @version v1.0
 */
@Controller
@RequestMapping("/batchSetting")
public class BatchSettingController {

    private final Logger logger = LoggerFactory.getLogger( BatchSettingController.class );

    @Autowired
    private BatchSettingService batchSettingService;

    @GetMapping("list")
    @ResponseBody
    public JsonResponse list(PageDTO pageDTO,BatchSetting batchSetting){
        Page<BatchSetting> page= batchSettingService.pageList(pageDTO,batchSetting);
        return JsonResponse.success(page);
    }

    @PostMapping("batch/insert")
    @ResponseBody
    public  JsonResponse batchInsert(BatchSetting batchSetting){
        System.out.println("111111111111111111111111111111111111111");
//        batchSetting.registerCustomEditor(Date.class, new CustomDateEditor(
//                new SimpleDateFormat("yyyy-MM-dd"), true));
        System.out.println(batchSetting);
        if(!batchSetting.equals("null")){
            batchSettingService.save(batchSetting);
            return JsonResponse.success(true);
        }
        return JsonResponse.success(false);
    }
}

